﻿/**
 * @author Administrator
 */
/**
 * 删除文件或文件夹选择效果
 */
function allMsgCheck(){
    var chks = document.getElementsByTagName("input");
    for (var i = 0; i < chks.length; i++) {
        var chkCur = chks[i];
        if (chkCur.type.toLowerCase() == "checkbox" && chkCur.name != "allChk") {
            if (chkCur.checked == false) {
                chkCur.checked = true;
            }
            else {
                chkCur.checked = false;
            }
        }
    }
}

/**
 * 检查是否有文件或文件夹被选中
 */
function checkSelectFileOrFolder(){
    state = false;
    var chks = document.getElementsByTagName("input");
    for (var i = 0; i < chks.length; i++) {
        var chkCur = chks[i];
        if (chkCur.type.toLowerCase() == "checkbox" && chkCur.name != "allChk") {
            if (chkCur.checked == true) {
                state = true;
                break;
            }
        }
    }
    if (state == true) {
        return true;
    }
    else {
        alert('请选择您要操作的文件或文件夹！');
        return false;
    }
}

/**
 * 上传文件显示等待指示条
 */
function uploadFile(){
    state = false;
    if (document.getElementById("FileUpload1").value != "") {
        state = true;
    }
    if (document.getElementById("FileUpload2").value != "") {
        state = true;
    }
    if (document.getElementById("FileUpload3").value != "") {
        state = true;
    }
    if (state == false) {
        alert("请选择您要上传的文件");
        return false;
    }
    else {
        document.getElementById("toUpload").style.display = 'none';
        document.getElementById("uploading").style.display = 'inline';
		return true;
    }
}

/**
 * 检查新建文件夹名字是否为空
 * @param {Object} target
 */
function checkNewCatalogFolderName(target){
	if(document.getElementById(target).value == ""){
		alert("请输入合法的文件夹名称！");
		return false;
	}
	return true;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
function moveSelectEmp(willSelectLbxName, selectTargetLbxName, target){
    var willSelect = document.getElementById(willSelectLbxName);
    var targetSelect = document.getElementById(selectTargetLbxName);
    var s = 0;
    for (var i = 0; i < willSelect.options.length; i++) {
        if (willSelect.options[i].selected) {
            var myOp = willSelect.options[i];
            targetSelect.appendChild(myOp);
            myOptionsLabel[s] = myOp.text;
            s++;
            i--;
        }
    }
    myOptions = new Array();
    if (target == 'right') {
        for (var x = 0; x < willSelect.options.length; x++) {
            myOptions[x] = willSelect.options[x];
        }
    }
    else {
        for (var x = 0; x < targetSelect.options.length; x++) {
            myOptions[x] = targetSelect.options[x];
        }
    }
}

function moveALLSelectEmp(willSelectLbxName, selectTargetLbxName, target){
    var willSelect = document.getElementById(willSelectLbxName);
    var targetSelect = document.getElementById(selectTargetLbxName);
    var s = 0;
    for (var i = 0; i < willSelect.options.length;) {
        var myOp = willSelect.options[i];
        targetSelect.appendChild(myOp);
        myOptionsLabel[s] = myOp.text;
        s++;
    }
    myOptions = new Array();
    if (target == 'right') {
        for (var x = 0; x < willSelect.options.length; x++) {
            myOptions[x] = willSelect.options[x];
        }
    }
    else {
        for (var x = 0; x < targetSelect.options.length; x++) {
            myOptions[x] = targetSelect.options[x];
        }
    }
}

/////////////////////////////////////////////////////////////////////////
var myOptions = new Array();
var myOptionsLabel = new Array();

function loadOptions(target){
    var targets = document.getElementById(target);
    for (var i = 0; i < targets.options.length; i++) {
        myOptions[i] = targets.options[i];
    }
}

function willSelectOneTxtValueChange(resource, target){
    var resource = document.getElementById(resource);
    var target = document.getElementById(target);
    clearOptions(target);
    if (resource.value != "") {
        for (var j = 0; j < myOptions.length; j++) {
            var myTarOp = myOptions[j];
            if (resource.value.toLowerCase() == myTarOp.text.toLowerCase().substr(0, resource.value.length)) {
                target.appendChild(myTarOp);
            }
        }
        if (target.options.length == 0) {
            selectOneValueChange(myOptions, target);
        }
    }
    else {
        selectOneValueChange(myOptions, target);
    }
}

function selectOneValueChange(myOptions, target){
    for (var m = 0; m < myOptions.length; m++) {
        target.appendChild(myOptions[m]);
    }
}

function clearOptions(target){
    for (var i = 0; i < target.options.length;) {
        target.removeChild(target.options[i]);
    }
}

/////////////////////////////////////////////////////////////////////

/**
 * 检查已选人员是否为空
 * @param {Object} target
 */
function checkOpUsers(target){
	var myOp = document.getElementById(target);
	if(myOp.options.length == 0){
		alert("已选人员不能为空！");
		return false;
	}
	else{
		for(var i = 0; i < myOp.options.length; i++){
			myOp.options[i].selected = true;
		}
	}
	return true;
}

/**
 * 选中所有部门
 */
function checkAllSections(){
	var chks = document.getElementsByTagName("input");
	for(var i = 0; i < chks.length; i++){
		if(chks[i].type == "checkbox" && chks[i].checked == false){
			chks[i].checked = true;
		}
	}
}

